package com.skateboard.reelviewtest.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.skateboard.reelviewtest.R;

/**
 * -------------------------------------
 * 作者：腾超杰
 * -------------------------------------
 * 时间：2020/11/25 5:47 PM
 * -------------------------------------
 * 描述：礼物墙排序标签View
 * -------------------------------------
 * 备注：
 * -------------------------------------
 */
public class GiftWallSortTab extends FrameLayout {

    /**
     * order,正序倒序
     */
    private boolean order = false;

    private TextView tvName;
    private View indicator;
    private ImageView ivIcon;

    public GiftWallSortTab(Context context) {
        this(context, null);
    }

    public GiftWallSortTab(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GiftWallSortTab(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.giftwall_sort_tab, this, true);
        tvName = findViewById(R.id.tv_name);
        indicator = findViewById(R.id.indicator);
        ivIcon = findViewById(R.id.iv_icon);
    }

    public void selected(String name) {
        order = !order;
        tvName.setText(name);
        tvName.setTextColor(getContext().getResources().getColor(R.color.color_864F3D));
        indicator.setVisibility(VISIBLE);
        if (order) {
            ivIcon.setImageResource(R.mipmap.kl_icon_gift_sort_arrow_up);
        } else {
            ivIcon.setImageResource(R.mipmap.kl_icon_gift_sort_arrow_down);
        }
    }

    public void unSelected(String name) {
        tvName.setText(name);
        tvName.setTextColor(getContext().getResources().getColor(R.color.color_A3634F));
        indicator.setVisibility(INVISIBLE);
        ivIcon.setImageResource(R.mipmap.kl_icon_gift_sort_arrow);
    }
}
